# encoding: utf-8

import pyautogui
import pyperclip
import time

class MouseUtil:
    def __init__(self):
        pass

    @classmethod
    def click(cls, x, y, key='left'):
        try:
            if key == "right":
                pyautogui.rightClick(x,y)
            else:
                pyautogui.click(x, y)
        except pyautogui.FailSafeException:
            return False

    @classmethod
    def middleMove(cls, x, y, duration=0.2):
        try:
            pyautogui.middleClick()
            pyautogui.dragRel(x,y,duration=duration)
        except pyautogui.FailSafeException:
            return False

    @classmethod
    def moveTo(cls,distancex,distancey):
        (x,y) = pyautogui.position()
        pyautogui.moveTo(x+distancex,y+distancey,2)

    @classmethod
    def move(cls,x,y):
        try:
            #pyautogui.FAILSAFE = False
            pyautogui.move(x,y)
        except:
            pass

    @classmethod
    def doubleClick(cls,x,y):
        try:
            pyautogui.doubleClick(x,y)
        except pyautogui.FailSafeException:
            return False

    @classmethod
    def scroll(cls,x):
        try:
            pyautogui.scroll(x)
        except:
            return False

    @classmethod
    def drageTo(cls, x1, y1, x2 ,y2):
        cls.click(x1,y1)
        pyautogui.dragTo(x2, y2, 2, button='left')

    @classmethod
    def paste(cls, x1, y1, txt):
        pyperclip.copy(txt)
        pyautogui.rightClick(x1, y1)
        time.sleep(0.5)
        pyautogui.click(x1+28, y1+90)
